package rozetka.utils;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;

import java.util.concurrent.TimeUnit;

public class WebDriverFactory {

    /* Browsers constants */
    public static final String CHROME = "chrome";
    public static final String FIREFOX = "firefox";
    public static final String INTERNET_EXPLORER = "ie";
    public static final String HTML_UNIT = "htmlunit";

    /* Firefox profiles */
    public static final String DEFAULT_PROFILE = "default";

    public static WebDriver initDriver(String browser)
    {
        WebDriver testDriver = null;

        if (browser.equals(FIREFOX)){
            testDriver = new FirefoxDriver();
        } else if (browser.equals(CHROME)) {
            testDriver = new ChromeDriver();
        } else if (browser.equals(INTERNET_EXPLORER)){
            testDriver = new InternetExplorerDriver();
        } else if (browser.equals(HTML_UNIT)) {
            testDriver = new HtmlUnitDriver();
        } else {
            Assert.fail(ReportWriter.errorDriverUnknown(browser));
        }
        //additional configuration
        testDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ReportWriter.info(browser +" has started");
        return testDriver;
    }
}